package br.com.arg.aplica.rest;

import java.util.List;

import javax.enterprise.context.RequestScoped;
import javax.inject.Inject;
import javax.persistence.EntityManager;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;

import br.com.arg.aplica.model.Classe;;

/**
 * JAX-RS Example
 * 
 * This class produces a RESTful service to read the contents of the members table.
 */
@Path("/formatos")
@RequestScoped
public class FormatoResourceRESTService {
   @Inject
   private EntityManager em;

   @GET
   @Produces("text/xml")
   public List<Classe> listAllFormatos() {
      // Use @SupressWarnings to force IDE to ignore warnings about "genericizing" the results of
      // this query
      @SuppressWarnings("unchecked")
      // We recommend centralizing inline queries such as this one into @NamedQuery annotations on
      // the @Entity class
      // as described in the named query blueprint:
      // https://blueprints.dev.java.net/bpcatalog/ee5/persistence/namedquery.html
      final List<Classe> results = em.createQuery("select f from Formato f order by f.formato").getResultList();
      return results;
   }

   @GET
   @Path("/{id:[A-Z][A-Z0-9]*}")
   @Produces("text/xml")
   public Classe lookupFormatoById(@PathParam("id") String id) {
		System.out.println("<<<<<<<<<<<<<<<<<<<<<<<<<<<< Formato=" + id);
      return em.find(Classe.class, id);
   }
}
